package cn.wyz.org.service.impl;

import cn.wyz.basic.query.BaseQuery;
import cn.wyz.basic.service.impl.BaseServiceImpl;
import cn.wyz.org.domain.DictionaryDetail;
import cn.wyz.org.domain.SystemDictionaryType;
import cn.wyz.org.mapper.DictionaryDetailMapper;
import cn.wyz.org.mapper.SystemDictionaryTypeMapper;
import cn.wyz.org.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class SystemDictionaryTypeServiceImpl extends BaseServiceImpl<SystemDictionaryType> implements ISystemDictionaryTypeService {
    @Autowired
    private SystemDictionaryTypeMapper mapper;
    @Autowired
    private DictionaryDetailMapper detailMapper;

    /**
     * 删除产品类型,会连带删除对应类型id的商品明细
     * @param id
     */
    @Override
    @Transactional
    public void deleteById(Long id) {
        List<DictionaryDetail> details = detailMapper.selectAll();
        for (DictionaryDetail detail : details) {
            if(detail.getTypes_id()==id){
                detailMapper.deleteById(detail.getId());
            }
        }
        mapper.deleteById(id);
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> idList) {
        for (Long id : idList) {
            this.deleteById(id);
        }
        mapper.patchDel(idList);
    }



}
